package com.d0318;

import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

public class Resourse {
    public void f() {

        System.out.println(Thread.currentThread().getName()+"not...");
        synchronized (this){
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName() + "fun()is running");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    }

        public void g(){
            System.out.println(Thread.currentThread().getName()+"000000");
            synchronized (this) {
                for (int i = 0; i < 5; i++) {
                    System.out.println(Thread.currentThread().getName() + "g()is running");
                    try {
                        TimeUnit.SECONDS.sleep(2);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
    }

    public void h(){
        System.out.println(Thread.currentThread().getName()+"000000");
        synchronized (this) {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + "h()is running");
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        Resourse resourse = new Resourse();
        new Thread(()->resourse.f()).start();
        new Thread(()->resourse.g()).start();
        resourse.h();
    }
}

//class MyThread extends Thread{
//    Resourse resourse = new Resourse();
//
//    @Override
//    public void run() {
//        resourse.f();
//    }
//}
